package com.bangdao.app.jetpacktest.jetpack.databinding;

import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;
import androidx.lifecycle.ViewModelProvider;

import com.bangdao.app.jetpacktest.R;
import com.bangdao.app.jetpacktest.databinding.ActivityTwoWayDataBinding2Binding;
import com.bangdao.app.jetpacktest.jetpack.databinding.viewmodel.TwoWayBindingViewModel2;

/**
 * 双向绑定
 */
public class TwoWayDataBindingActivity2 extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        //创建DataBinding
        ActivityTwoWayDataBinding2Binding binding =
                DataBindingUtil.setContentView(this, R.layout.activity_two_way_data_binding2);
        //创建ViewModel
        TwoWayBindingViewModel2 viewModel2 = new ViewModelProvider(this).get(TwoWayBindingViewModel2.class);
        //建立绑定关系
        binding.setViewModel(viewModel2);
    }
}